<template>
  <div>
    <el-row :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
      <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="xlSize">
        <el-form-item label="创建人" prop="createUser">
          <el-input v-model="createUser" placeholder="请输入创建人" :disabled="true" />
        </el-form-item>
      </el-col>

      <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="xlSize">
        <el-form-item label="创建时间" prop="dtCreateDate">
          <el-date-picker
            clearable
            size="small"
            style="width:100%;"
            v-model="dtCreateDate"
            type="datetime"
            disabled="disabled"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择创建时间"
          ></el-date-picker>
        </el-form-item>
      </el-col>

      <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="xlSize">
        <el-form-item label="更新人" prop="updateUser">
          <el-input v-model="updateUser" placeholder="请输入更新人" :disabled="true" />
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="xlSize">
        <el-form-item label="更新时间" prop="dtUpdateDate">
          <el-date-picker
            clearable
            size="small"
            style="width:100%;"
            v-model="dtUpdateDate"
            type="datetime"
            disabled="disabled"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择更新时间"
          ></el-date-picker>
        </el-form-item>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import { parseTime } from '@/utils/ruoyi'
  import request from '@/utils/request'
  export default {
    name: 'CreateInfo',
    props: {
      ctCreateUser: {
        type: String,
      },
      dtCreateDate: {
        type: String,
        default: parseTime(new Date()),
      },
      ctUpdateUser: {
        type: String,
      },
      dtUpdateDate: {
        type: String,
        default: parseTime(new Date()),
      },
      updateCreateInfo:{
        type:String | Boolean,
        default:null
      },
      xlSize: {
        type: Number,
        default: 6,
      },
    },
    data() {
      return {
        firstValue1: true,
        firstValue2: true,
        createUser:this.ctCreateUser || this.$store.state.user.nickName,
        updateUser:this.ctUpdateUser || this.$store.state.user.nickName,
      }
    },
    computed:{
      // createUser(){
      //   return this.ctCreateUser || this.$store.state.user.name
      // },
      // updateUser(){
      //   return this.ctUpdateUser || this.$store.state.user.name
      // }
    },
    mounted() {
      // this.createUser=this.ctCreateUser
      // this.updateUser=this.ctUpdateUser
    },
    watch: {
      updateCreateInfo:{
        handler: function (val, oldval) {
          this.setDefault("1")
          this.setDefault("2")
        },
        immediate: true,
      },
    },

    methods:{
      tableData(query) {
        return request({
          url: '/mis/cache/username?username='+query.ct_id,
          method: 'get',
        })
      },
      setDefault(vv) {
        let v = "";
        if (vv == "1")
          v = this.ctCreateUser;
        else
          v = this.ctUpdateUser;
        let query = {
          ct_id: v
        }
        this.tableData(query).then(
          (response) => {
            if (!response.nickName) return;
            if (vv == "1") {
              this.createUser = response.nickName;
              this.firstValue1 = false;
            } else {
              this.updateUser = response.nickName;
              this.firstValue2 = false;
            }
          }
        )
      }
    }
  }
</script>
